package ast;

import java.util.ArrayList;

import symbol.astPreprocessContext;

public class FuncDef extends AstItem {
	// 函数定义
	public AstItem funcSignature;
	public AstItem funcBlock;
	
	public String toString() {
		return funcSignature.toString() + " " + funcBlock.toString() + "\n\n";
	}
	
	public void preprocess(AstItem father) {
		// 处理funcBlock的时候，传入funcSignature
		assert funcSignature instanceof FunctionSignature;
		if (((FunctionSignature) funcSignature).signatureType != FunctionSignature.SignatureType.FUNC_DEF) {
			// 类的构造器或者是类的方法，则传入类
			funcSignature.preprocess(father);
			funcBlock.preprocess(funcSignature);
		} else {
			// 否则就直接下去就行
			funcSignature.preprocess(this);
			funcBlock.preprocess(funcSignature);
		}
		astPreprocessContext.getContext();
		astPreprocessContext.removeNowFuncKey();
	}

	@Override
	public String toJsonString() {
		String json = "{";
		json += "\"Type\": \"FuncDef\",";
		json += "\"Head\": ";
		json += funcSignature.toJsonString() + ",";
		json += "\"FuncBlock\": ";
		json += funcBlock.toJsonString();
		json += "}";
		return json;
	}
}
